<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<li style="<%= hidden if is_hidden %>" class="event">

<%
  recent_feedback ||= nil
  show_context ||= false
  comment = nil
  grade = nil
  score = nil

  # current user needs to be in the cache key to bust the cache when they change course nicknames
  cache(['recent_feedback_render3', @current_user, recent_feedback || 'blank_feedback', Time.zone.utc_offset].cache_key) do
    context = recent_feedback.context
    assignment = recent_feedback.assignment
    url = context_url(context, :context_assignment_submission_url, :assignment_id => recent_feedback.assignment_id, :id=>@current_user.id)
    grade = readable_grade(recent_feedback)
    score = recent_feedback.score
    comment = recent_feedback.last_teacher_comment
    comment_text = HtmlTextHelper.strip_and_truncate(comment.comment, :max_length => 120) if comment
    icon_explanation, _, icon_class = icon_data(:context => context,
                                             :current_user => @current_user,
                                             :recent_event => assignment,
                                             :submission => recent_feedback,
                                             :student_only => true)
  %>

  <a
    data-track-category="dashboard"
    data-track-label="recent feedback"
    class="recent_feedback_icon" href="<%= url %>"
  >
    <i class="<%= icon_class %>"></i>
    <div class="event-details">
      <% if comment && comment.media_comment? %>
        <% kaltura_thumbnail_url = CanvasKaltura::ClientV3.new.thumbnail_url(comment.media_comment_id, :width => 50, :height => 35, :bgcolor => "F3F4F5") %>
        <img src="<%= kaltura_thumbnail_url %>" style="max-width: 50px; max-height: 35px; float: right; padding-left: 3px;" alt=""/>
      <% end %>
      <b class="event-details__title recent_feedback_title">
        <%= recent_feedback.assignment.title %>
      </b>
      <% if show_context %>
        <p class="event-details__context">
          <%= context.nickname_for(@current_user, :short_name) %>
        </p>
      <% end %>
      <% if grade %>
        <p><strong><%= grade %></strong></p>
      <% end %>
      <% if comment_text %>
        <p>"<%= comment_text %>"</p>
      <% end %>
    </div>
    <div class="clear"></div>
  </a>
  <div class="clear"></div>

<% end %>

</li>
